import React, { Component } from 'react'
import querystring from 'querystring'

export default class Detail extends Component {
  constructor(props) {
    super(props);
    this.state = {
      // params
      id: this.props.match.params.id
    }
    // state
    console.log(this.props.location.state);

    // query参数
    // console.log(querystring.parse(this.props.location.search.slice(1)))
    // new URLSearchParams(this.props.location.search.slice(1)).get('name')
    /* let objArr = new URLSearchParams(this.props.location.search.slice(1)).entries()
    for(let [key,value] of objArr){
      console.log(key,value);
    } */

  }

  // 只要有props或state有数据更新就会执行
  static getDerivedStateFromProps(props,state){
    console.log(props);
    return props.match.params
  }

  render() {
    return (
      <div>
        详情页面 -- {this.state.id}
      </div>
    )
  }
}
